package socket.socket01;

import java.io.*;

public class SocketClient {
    public static void main(String[] args) {
        SocketClient sc = new SocketClient();
        sc.client();
    }

    public void client() {
        OutputStream outputStream = null;
        InputStream inputStream = null;
        BufferedReader br = null;
        try {
            //和服务端创建连接
            java.net.Socket socket = new java.net.Socket("localhost", 8088);
            outputStream = socket.getOutputStream();
            PrintWriter printWriter = new PrintWriter(outputStream);
            printWriter.write("客户端发送信息");
            printWriter.flush();
            socket.shutdownOutput();
            //从服务端接受消息
            inputStream = socket.getInputStream();
            br = new BufferedReader(new InputStreamReader(inputStream));
            String info = null;
            while ((info = br.readLine()) != null) {
                System.out.println("我是客户端，服务器返回信息：" + info);
            }
            outputStream.close();
            inputStream.close();
            br.close();
            socket.close();
        } catch (Exception ex) {

        }
    }
}
